home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TMagicMacros Delphi / TMM2_D4T / MACRO_RE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-19  |  7.2 KB  |  226 lines

  1. unit macro_rec_f;
  2.   /////////////////////////////////////////////////////////
  3.   //                                                     //
  4.   //           TMagicMacros-Component v2.0               //
  5.   //                                                     //
  6.   // (C) Niels Vanspauwen, 15/10/98                      //
  7.   //     E-mail: Niels.Vanspauwen@Kagi.com               //
  8.   //     Homepage: http://magicmacros.8m.com             //
  9.   //                                                     //
  10.   /////////////////////////////////////////////////////////
  11.   {This is another demoproject that comes with TMagicMacros component.
  12.    This one demonstrates how easy it is to include macro support for
  13.    your users in no time !
  14.    Following methods are clearly illustrated in this demoproject:
  15.    Play, StartRecording, StopRecording, Pause, Resume, ShowInfoBox,
  16.    WaitForInfoBox.
  17.    Most events are illustrated also.
  18.  
  19.    USAGE:
  20.    ------
  21.    Click on File-New to assign a name to your macro. (extension is
  22.    automatically set to .mcr, regardless of the extension you give)
  23.    Now press the "Record"-button and move around with the mouse a bit.
  24.    Click on the "Test Auto-speed Addaption"-button. This performs a
  25.    very simple loop: the computer starts counting from 1 to 1000.
  26.    Notice that you cannot move the cursor while the PC is performing
  27.    this loop.
  28.    When the loop is done, click on the "Stop Recording"-button.
  29.    The macro is automatically saved to disk.
  30.    Now press the "Play"-button and playback will start.
  31.    Not impressed ? After the playback has ended, set one of the
  32.    radio-buttons to "Simulate 5x slower" or "Simulate 5x faster" and
  33.    press play again. As you'll notice, the macro nicely waits untill
  34.    the PC is done counting before playback continues !
  35.    Be sure to check the docs that come with this component to read all
  36.    about the "how and why" of this feature.
  37.    }
  38.  
  39. interface
  40.  
  41. uses
  42.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  43.   StdCtrls, Menus, ExtCtrls, Buttons, Gauges;
  44.  
  45. type
  46.   TRecorderForm = class(TForm)
  47.     RecordButton: TButton;
  48.     StopButton: TButton;
  49.     PlayButton: TButton;
  50.     MainMenu1: TMainMenu;
  51.     File1: TMenuItem;
  52.     New1: TMenuItem;
  53.     Open1: TMenuItem;
  54.     N1: TMenuItem;
  55.     Exit1: TMenuItem;
  56.     OpenDialog1: TOpenDialog;
  57.     Button1: TButton;
  58.     RadioGroup1: TRadioGroup;
  59.     Edit1: TEdit;
  60.     Gauge: TGauge;
  61.     MagicMacros: TMagicMacros;
  62.     procedure RecordButtonClick(Sender: TObject);
  63.     procedure StopButtonClick(Sender: TObject);
  64.     procedure PlayButtonClick(Sender: TObject);
  65.     procedure FormCreate(Sender: TObject);
  66.     procedure New1Click(Sender: TObject);
  67.     procedure Open1Click(Sender: TObject);
  68.     procedure Exit1Click(Sender: TObject);
  69.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  70.     procedure MagicMacrosPlayEnded(Sender: TObject);
  71.     procedure MagicMacrosRecordEnded(Sender: TObject);
  72.     procedure Button1Click(Sender: TObject);
  73.     procedure MagicMacrosPlay(Sender: TObject);
  74.     procedure Edit1Click(Sender: TObject);
  75.     procedure MagicMacrosProgress(PercentDone: Integer);
  76.   end;
  77.  
  78. var
  79.   RecorderForm: TRecorderForm;
  80.  
  81. implementation
  82.  
  83. {$R *.DFM}
  84.  
  85. procedure TRecorderForm.RecordButtonClick(Sender: TObject);
  86. begin
  87.   RecordButton.Enabled := false;
  88.   PlayButton.Enabled := False;
  89.   StopButton.Enabled := true;
  90.   MagicMacros.StartRecording;
  91. end; {procedure RecordButtonClick}
  92.  
  93.  
  94. procedure TRecorderForm.StopButtonClick(Sender: TObject);
  95. begin
  96.   Gauge.Progress := 0;
  97.   Gauge.Visible := true;
  98.   MagicMacros.StopRecording;
  99. end; {procedure StopButtonClick}
  100.  
  101.  
  102. procedure TRecorderForm.PlayButtonClick(Sender: TObject);
  103. begin
  104.   try
  105.     Gauge.Progress := 0;
  106.     Gauge.Visible := true;
  107.     MagicMacros.Play;
  108.   except on ENoSuchMacro do
  109.     ShowMessage('Macro does not exist !');
  110.   end; {exception handler}
  111. end; {procedure PlayButtonClick}
  112.  
  113.  
  114. procedure TRecorderForm.FormCreate(Sender: TObject);
  115. begin
  116.   RecordButton.Enabled := false;
  117.   PlayButton.Enabled := false;
  118.   StopButton.Enabled := false;
  119. end;
  120.  
  121. procedure TRecorderForm.New1Click(Sender: TObject);
  122. var
  123.   Filename: String;
  124. begin
  125.   if InputQuery('New macro', 'Enter name for macro:', Filename) then begin
  126.     //Check if file already exists:
  127.     if FileExists(ChangeFileExt(Filename, '.mcr')) and
  128.       (MessageDlg('A macro with the name '+ChangeFileExt(Filename, '.mcr')+#13+
  129.                   'already exists! Do you want to overwrite it ?', mtWarning,
  130.                   [mbYes, mbNo], 0)=idNo) then exit;
  131.     MagicMacros.MacroName := ChangeFileExt(Filename, '.mcr');
  132.     Caption := ChangeFileExt(Filename, '');
  133.     RecordButton.Enabled := true;
  134.     PlayButton.Enabled := true;
  135.     StopButton.Enabled := false;
  136.   end;
  137. end;
  138.  
  139. procedure TRecorderForm.Open1Click(Sender: TObject);
  140. begin
  141.   if OpenDialog1.execute then begin
  142.     MagicMacros.MacroName := OpenDialog1.Filename;
  143.     Caption := ChangeFileExt(OpenDialog1.Filename, '');
  144.     RecordButton.Enabled := true;
  145.     PlayButton.Enabled := true;
  146.     StopButton.Enabled := false;
  147.   end;
  148. end;
  149.  
  150. procedure TRecorderForm.Exit1Click(Sender: TObject);
  151. begin
  152.   Close;
  153. end;
  154.  
  155. procedure TRecorderForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  156. begin
  157.   if MessageDlg('Are you sure you want to exit ?', mtConfirmation,
  158.                 [mbYes, mbNo],0)=idYes then
  159.     CanClose := true
  160.     else CanClose := false;
  161. end;
  162.  
  163. procedure TRecorderForm.MagicMacrosPlayEnded(Sender: TObject);
  164. begin
  165.   RecordButton.Enabled := true;
  166.   PlayButton.Enabled := true;
  167. end;
  168.  
  169. procedure TRecorderForm.MagicMacrosRecordEnded(Sender: TObject);
  170. begin
  171.   RecordButton.Enabled := true;
  172.   PlayButton.Enabled := true;
  173.   StopButton.Enabled := false;
  174.   Gauge.Visible := false;
  175. end;
  176.  
  177. procedure TRecorderForm.Button1Click(Sender: TObject);
  178. var
  179.   i: integer;
  180.   Counter: integer;
  181.   Text: string;
  182. begin
  183.   MagicMacros.Pause; //This method-call is needed for the auto-speed adaption.
  184.   Text := 'Just testing this great new feature: use idle time to give the user'+
  185.           'some information about your application. The macro waits for the '+
  186.           'box to disappear before continuing playback!'+#13+
  187.           'Note that you have to call Pause and Resume before, resp. after'+
  188.           'making a call to the ShowInfoBox-method for this...';
  189.   MagicMacros.ShowInfoBox('Testing', Text, 5000);
  190.   if RadioGroup1.ItemIndex = 0 then
  191.     Counter := 5000
  192.   else if RadioGroup1.ItemIndex = 1 then
  193.     Counter := 1000
  194.   else Counter := 200;
  195.   for i := 1 to Counter do begin
  196.     Caption := IntToStr(i);
  197.   end;
  198.   MagicMacros.WaitForInfoBox;
  199.   MagicMacros.Resume; //This method-call is needed for the auto-speed adaption.
  200. end;
  201.  
  202. procedure TRecorderForm.MagicMacrosPlay(Sender: TObject);
  203. begin
  204.   PlayButton.Enabled := false;
  205.   RecordButton.Enabled := False;
  206.   StopButton.Enabled := false;
  207.   Gauge.Visible := false;
  208. end;
  209.  
  210.  
  211. procedure TRecorderForm.Edit1Click(Sender: TObject);
  212. begin
  213.   {Select the text in the editbox}
  214.   Edit1.SelStart := 0;
  215.   Edit1.SelLength := Length(Edit1.Text);
  216. end;
  217.  
  218.  
  219. procedure TRecorderForm.MagicMacrosProgress(PercentDone: Integer);
  220. begin
  221.   if (PercentDone mod 5) = 0 then
  222.     Gauge.Progress := PercentDone;
  223. end;
  224.  
  225. end.
  226.